package com.zhuxuehuang.firstandroid;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.RadioButton;
import android.widget.Toast;

import java.sql.BatchUpdateException;

public class TwoActivity extends AppCompatActivity {
    private Button button_two;
    private RadioButton radio1;
    private RadioButton radio2;
    private RadioButton radio3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_two);

        button_two = (Button) findViewById(R.id.button_two);
        button_two.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(TwoActivity.this, ThreeActivity.class);
                startActivity(intent);
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main2, menu);
        return true;
    }

    public void radioClick(View view) {
        RadioButton radio = (RadioButton) view;
        boolean radio_isChecked = radio.isChecked();
        switch (view.getId()) {
            case R.id.radioButton1:
                if (radio_isChecked) {
                    Toast.makeText(TwoActivity.this, "男" + radio.getText(), 1).show();
                } else {
                    Toast.makeText(TwoActivity.this, "男else", 1).show();
                }
                break;
            case R.id.radioButton2:
                if (radio_isChecked) {
                    Toast.makeText(TwoActivity.this, "女" + radio.getText(), 1).show();
                } else {
                    Toast.makeText(TwoActivity.this, "女else", 1).show();
                }
                break;
            case R.id.radioButton3:
                if (radio_isChecked) {
                    Toast.makeText(TwoActivity.this, "保密" + radio.getText(), 1).show();
                } else {
                    Toast.makeText(TwoActivity.this, "保密else", 1).show();
                }
                break;
        }
    }

    public void checkboxClick(View view) {
        CheckBox checkbox = (CheckBox) view;
        boolean isChecked = checkbox.isChecked();
        switch (view.getId()) {
            case R.id.checkBox:
                if (isChecked) {
                    Toast.makeText(TwoActivity.this,  checkbox.getText(), 1).show();
                } else {
                    Toast.makeText(TwoActivity.this,  checkbox.getText() + "else", 1).show();
                }
                break;
            case R.id.checkBox2:
                if (isChecked) {
                    Toast.makeText(TwoActivity.this,  checkbox.getText(), 1).show();
                } else {
                    Toast.makeText(TwoActivity.this,  checkbox.getText() + "else", 1).show();
                }
                break;
            case R.id.checkBox3:
                if (isChecked) {
                    Toast.makeText(TwoActivity.this,  checkbox.getText(), 1).show();
                } else {
                    Toast.makeText(TwoActivity.this,  checkbox.getText() + "else", 1).show();
                }
                break;
        }
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
